package com.crm.common.model;

import com.crm.common.model.Enum.ResponseCodeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author luojie
 * @date 2020/10/15 8:47
 */
public class DhResponse extends DataResponse {
    protected static Logger log = LoggerFactory.getLogger(DhResponse.class);

    public DhResponse(String code) {
        super();
        setCode(code);
        try {
            String message = ResponseCodeEnum.getEnumValueByResponseCode(code);
            setMessage(message);
        } catch (Exception e) {
            log.error("DhDateResponse getMessage ERROR:", e);
            setMessage(code);
        }
    }

    public DhResponse(String code, String errorDetail, Object data) {
        super();
        setCode(code);
        try {
            String message = ResponseCodeEnum.getEnumValueByResponseCode(code);
            setMessage(message);
        } catch (Exception e) {
            log.error("DhDateResponse getMessage ERROR:", e);
            setMessage(code);
        }
        setData(data);
        setErrorDetail(errorDetail);
    }

    public DhResponse(String code, Object data) {
        super();
        setCode(code);
        try {
            String message = ResponseCodeEnum.getEnumValueByResponseCode(code);
            setMessage(message);
        } catch (Exception e) {
            log.error("DhDateResponse getMessage ERROR:", e);
            setMessage(code);
        }
        setData(data);
    }

    public DhResponse(String code, DhPageInfo<?> data) {
        super();
        setCode(code);
        try {
            String message = ResponseCodeEnum.getEnumValueByResponseCode(code);
            setMessage(message);
        } catch (Exception e) {
            log.error("DhDateResponse getMessage ERROR:", e);
            setMessage(code);
        }
        if (data != null) {
            setData(data.getList());
            setPageIndex(data.getPageIndex());
            setPageSize(data.getPageSize());
            setTotalPages(data.getTotalPages());
            setTotalRecords(data.getTotalRecords());
        }
    }

    public DhResponse(String code, Object data, Integer pageIndex, Integer pageSize, Long totalRecords,
                      Integer totalPages) {
        super();
        setCode(code);
        try {
            String message = ResponseCodeEnum.getEnumValueByResponseCode(code);
            setMessage(message);
        } catch (Exception e) {
            log.error("DhDateResponse getMessage ERROR:", e);
            setMessage(code);
        }
        setData(data);
        setPageIndex(pageIndex);
        setPageSize(pageSize);
        setTotalPages(totalPages);
        setTotalRecords(totalRecords);
    }

    public DhResponse(String code, String errorDetail, Object data, Integer pageIndex, Integer pageSize,
                      Long totalRecords, Integer totalPages) {
        super();
        setCode(code);
        try {
            String message = ResponseCodeEnum.getEnumValueByResponseCode(code);
            setMessage(message);
        } catch (Exception e) {
            log.error("DhDateResponse getMessage ERROR:", e);
            setMessage(code);
        }
        setData(data);
        setErrorDetail(errorDetail);
        setPageIndex(pageIndex);
        setPageSize(pageSize);
        setTotalPages(totalPages);
        setTotalRecords(totalRecords);
    }
}
